<?php

class Quad_Router_HttpPlain extends Quad_Router_Abstract {
	
	public function __construct($url, $get) {
		$this->url = $url;
		$this->_get = $get;
		
		$pg = $this->_get['pg'];
		$this->_controllerName = 'index';
		$this->_actionName = 'index';
		if ($pg) {
			if (strpos($pg, '.')) {
				list ($this->_controllerName, $this->_actionName) = explode('.', $pg);
			} else {
				$this->_controllerName = $pg;
			}
		}
	}
	
  public function redirect($url, $getParams = array()) {
    if (!preg_match('~^[a-z+]+://~', $url)) {
      $url = HTTP_ROOT . "/$url";
    }
    if (count($getParams)) {
      $url .= '?' . http_build_query($getParams);
    }
    header("Location: $url");
    exit(0);
  }	
	
	public function buildUrl($controller = 'index', $action = 'index', $params = array(), $fragment = '') {
		$params['pg'] = "$controller.$action";
		$fragment = ($fragment ? "#$fragment" : '');
		return HTTP_ROOT . '?' . http_build_query($params) . $fragment;
	}
	
}